package com.daka.service.impl;

import com.daka.dao.UserDao;
import com.daka.entity.User;
import com.daka.service.UserService;
import com.daka.tools.wechatPay.UserInfo;
import com.daka.vo.db.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * Created by yangx
 * CreateTime: 2016/12/12 17:49
 */
@Service("userService")
@SuppressWarnings("unused")
public class UserServiceImpl implements UserService{

    @Resource
    private UserDao userDao;

    @Override
    public List<User> selectByTeam(Long teamId) {
        return userDao.selectByTeam(teamId);
    }

    @Override
    public User selectById(Long userId) {
        return userDao.selectByPrimaryKey(userId);
    }

    @Override
    public User selectByName(String userName, Long teamId) {
        return userDao.selectByUserNameAndTeam(userName, teamId);
    }

    @Override
    public boolean saveWX(UserInfo userInfo,Long userId) {
        User user = userDao.selectByPrimaryKey(userId);
        if(user != null){
            user.setHeadUrl(userInfo.getHeadimgurl());
//            userInfo.getUnionid()
            int i = userDao.updateByPrimaryKeySelective(user);
            if(i == 0){
                return true;
            }
        }
        return false;
    }

    @Override
    public int save(User user) {
        return userDao.insert(user);
    }

    @Override
    public int updateById(User user) {
        return userDao.updateByPrimaryKeySelective(user);
    }

    @Override
    public Integer selectUnDonationCount(Long teamId) {
        return userDao.selectUnDonationCount(teamId);
    }

    @Override
    public List<User> findBiggerByMoney(BigDecimal money) {
        return userDao.findBiggerByMoney(money);
    }

    @Override
    public List<UserInfoVo> findUserInfoVo() {
        return userDao.findUserInfoVo();
    }

    @Override
    public List<User> selectByTeamDonated(Long teamId) {
        return userDao.selectByTeamDonated(teamId);
    }

}
